module CheckData
	use ReadData, only: readMatrix, readVector
	implicit none
	contains
	
logical function matrixMatchExplanation(fileNamePrefixM,fileNamePrefixN,matrixSuffix)
	implicit none
	!检查前续时间步矩阵（对应fileNamePrefixM）和后续时间步矩阵（对应fileNamePrefixN）之间是否满足矩阵分块增长且分块的前导子矩阵保持不变的性质
	!此程序主要供选手参考矩阵的性质，实际测试过程中不会调用
	
	CHARACTER(LEN=*),intent(in) :: fileNamePrefixM,fileNamePrefixN,matrixSuffix
	real(kind=8), dimension(:,:), pointer :: matrixM,matrixN !线性方程组的矩阵
	
	
	integer :: neM, neN, i, j, deltne
	
	!读取矩阵
	call readMatrix(fileNamePrefixM,matrixSuffix,matrixM)
	neM = size(matrixM,1) / 2
	
	call readMatrix(fileNamePrefixN,matrixSuffix,matrixN)
	neN = size(matrixN,1) / 2
	
	
	deltne = neN - neM
	!分块检查矩阵
	if (deltne <= 0) then
		print *, "error in matrixMatchExplanation, neN should be larger than neM"
		pause
		stop
	end if
	
	matrixMatchExplanation = .true.
	do i = 1,neM
		do j = 1,neM
			if (abs(matrixM(i,j) - matrixN(i,j)) > 1.0e-6) then
				matrixMatchExplanation = .false.
				return
			end if
		end do
	end do
	
	do i = 1,neM
		do j = neM + 1, 2*neM
			if (abs(matrixM(i,j) - matrixN(i,j+deltne)) > 1.0e-6) then
				matrixMatchExplanation = .false.
				return
			end if
		end do
	end do
	
	do i = neM + 1,2*neM
		do j = 1,neM
			if (abs(matrixM(i,j) - matrixN(i + deltne,j)) > 1.0e-6) then
				matrixMatchExplanation = .false.
				return
			end if
		end do
	end do
	
	do i = neM + 1,2*neM
		do j = neM + 1,2*neM
			if (abs(matrixM(i,j) - matrixN(i+deltne,j+deltne)) > 1.0e-6) then
				matrixMatchExplanation = .false.
				return
			end if
		end do
	end do
	deallocate(matrixM,matrixN)
	
end function matrixMatchExplanation

	
	
end module	
